|
|
|
|
|
|
|
There is one final special case for colors. If you use the Point method to obtain a pixel's color and that pixel does not exist, Point returns 1 (&HFFFFFFFF). For example, if a form's ScaleMode property is vbPixels, then Point(10, 10) returns 1 because the location (10, 10) is off the form. |
|
|
|
|
|
|
|
|
The BreakColor subroutine shown in the following code combines these facts to separate a color into its components. The routine can handle normal RGB colors, system color indexes, and the noncolor value 1. If the color has value 1, BreakColor leaves its color component parameters unchanged. Depending on your application, you might want it to set the components to default values such as 0 or 255. |
|
|
|
 |
|
|
|
|
Private Declare Function GetSysColor Lib "user32" _
(ByVal nIndex As Long) As Long
' Break a color into its components. Private Sub BreakColor(ByVal color As Long, _
ByRef r As Long, ByRef g As Long, ByRef b As Long)
If color = &HFFFFFFFF Then Exit Sub
If color And &H80000000 Then _
color = GetSysColor(color And &HFFFFFF)
r = color And &HFF&
g = (color And &HFFOO&) \ &H100&
b = (color And &HFF0000) \ &H10000
End Sub |
|
|
|
|
|
|
|
|
Visual Basic also defines a group of 16 colors that make up the standard VGA color palette. The codes for these colors are used by some other versions of Basic like Microsoft Visual Basic for MS-DOS. You can use the QBColor function to convert these color codes into RGB values that you can use in Visual Basic like this: |
|
|
|
 |
|
|
|
|
color = QBColor(code) |
|
|
|
|
|
|
|
|
Table 1.6 shows the color codes in the VGA palette and the color represented by each. |
|
|
|
|
|
|
|
|
Example program QBColor, shown in Figure 1.31, displays the VGA colors palette. |
|
|
|
|
|
|
|
|
Figure 1.31
Example program QBColor displays the colors in the VGA palette. |
|
|
|
|
|